//
//  UIBarButtonItem+Extension.m
//  MainDemo
//
//  Created by FM on 2017/1/9.
//  Copyright © 2017年 FM. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"
#import "UIView+Extension.h"
@implementation UIBarButtonItem (Extension)
+ (instancetype)itemWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    button.size = button.currentBackgroundImage.size;
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[self alloc] initWithCustomView:button];
}
/*
 direction==1 leftBarButtonItem
 其他  rightBarButtonItem
 */
+ (instancetype)itemWithImage:(NSString *)image andDirection:(int)direction target:(id)target action:(SEL)action
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    button.size =CGSizeMake(50, 44) ;
    if (direction==1) {
        //        [button setContentEdgeInsets:UIEdgeInsetsMake(0, -30, 0, 10)];
        button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        [button setImageEdgeInsets:UIEdgeInsetsMake(0, 15, 0, 0)];
    }
    if (direction==2){
        //        [button setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -20)];
        button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
        [button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 15)];
    }
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[self alloc] initWithCustomView:button];
}
@end
